﻿using System;
using System.Collections.Generic;

namespace MyLinksMenu
{
	[Serializable]
	internal class SiteListItem
	{
		private string _Url = "";
		public string Url
		{
			get { return _Url; }
			set
			{
				//This is used to remove unnecessary ports from the URL, e.g., https://site.com:443/site/ becomes https://site.com/site/.
				Uri tempUri = new Uri(EnsureTrailingSlash(value));
				_Url = tempUri.ToString();
			}
		}

		public string Title { get; set; }

		public List<SiteListItem> SubSites;

		public void AddSubSite(SiteListItem site)
		{
			if (SubSites == null)
				SubSites = new List<SiteListItem>();

			SubSites.Add(site);
		}

		static string EnsureTrailingSlash(string url)
		{
			if (!url.EndsWith("/"))
				return url + "/";
			else
				return url;
		}
	}
}
